package servlet;

import pojo.Tbaseorder;
import pojo.Torderinfo;
import service.Impl.TorderServiceImpl;
import service.TorderService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/order/*")
public class TorderServlet extends HttpServlet {
    TorderService td = new TorderServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //获取路径
        String rURI = request.getRequestURI();
        //拆分字符串截取路径
        String[] split = rURI.split("/");
        String ss = split[split.length - 1];
        //细分
        String[] split1 = ss.split("\\?");
        String s = split1[0];
        if ("selall".equals(s)) {
            this.doselall(request, response);
        }
    }

    private void doselall(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Tbaseorder> todall = td.todall();
        request.setAttribute("all",todall);
        request.getRequestDispatcher("/orderList.jsp").forward(request,response);
    }
}
